// -----------------------------------------------
// Author:     code34 nicolas_boiteux@yahoo.fr
// Edited by:  Neumatic
// Warcontext: Add an addAction menu depending of target
// -----------------------------------------------

private [
	"_menurepair",
	"_name",
	"_target",
	"_vehicle",
	"_menurepairalone",
	"_menuunlock",
	"_menuunflip"
];

while {true} do {
	_target = cursorTarget;

	if (!(isNull _target) and (_target distance player < 10)) then {
		sleep 1;
		if (_target == cursorTarget) then {
			_name = getText (configFile >> "CfgVehicles" >> typeOf _target >> "DisplayName");
			_menurepair = nil;
			_menurepairalone = nil;
			_menuunlock = nil;
			_menuunflip = nil;

			_vehicle = vehicle player;

			// Repair point
			if (typeOf _target in wcrepairpointtype) then {
				_menurepair = _vehicle addAction [format ["<t color='#ffcb00'>%1</t>", _name], "warcontext\modules\wc_repairzone\WC_fnc_servicing.sqf", [], 6, false, true];
			};

			//A3 TODO: Add air?
			if (typeOf player in wcengineerclass) then {
				if (_target isKindOf "LandVehicle") then {
					_menurepairalone = player addAction ["<t color='#ffcb00'>" + localize "STR_WC_MENUREPAIRVEHICLE" + "</t>", "warcontext\actions\WC_fnc_dorepairvehicle.sqf", [], 6, false];
					_menuunlock = player addAction ["<t color='#ffcb00'>" + localize "STR_WC_MENUUNLOCKVEHICLE" + "</t>", "warcontext\actions\WC_fnc_dounlockvehicle.sqf", [], 6, false];
					_menuunflip = player addAction ["<t color='#ffcb00'>Unflip Vehicle</t>", "warcontext\actions\WC_fnc_dounflipvehicle.sqf", [], 6, false];
				};
			};

			while {_target == cursorTarget} do {
				sleep 1;
			};

			if !(isNil "_menurepair") then {_vehicle removeAction _menurepair};
			if !(isNil "_menurepairalone") then {player removeAction _menurepairalone};
			if !(isNil "_menuunlock") then {player removeAction _menuunlock};
			if !(isNil "_menuunflip") then {player removeAction _menuunflip};
		};
	};
	sleep 1;
};